<template>
    <div style="width:100%;height:95vh">
        <!-- <iframe style="width:100%;height:100%;" :src="path+'/public/m_toDicom.html?v='+Date.now()" frameborder="0"></iframe> -->
   <iframe style="width:100%;height:100%;" :src="dcmviewsrc" frameborder="0"></iframe>
  
    </div>
</template>

<script>
import {Toast} from 'vant';
export default {
    data: function() {
        return {
            path:this.$API.DOMAIN_NAME,
            isMobile:this.$isMobile,
            param: {
                account: '',
                password: '',
            },
            rules: {
                account: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
                password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
            },
            dcmviewsrc:'',
        };
    },
    mounted(){
        let role=this.getQueryVariable('role');
        console.log('role',role)
        if(role){
            if(role === 'jqsadmin'){
                this.param.account='jqjtlinkadmin';
                this.param.password='123456';
                this.submitForm();
                return;
            }

            if(role === 'jqoadmin'){
                this.param.account='jqjtlinkuser';
                this.param.password='123456';
                this.submitForm();
                return;
            }
        }

        //      // lianke =================
          let expires=this.getQueryVariable22('expires');
          let signature=this.getQueryVariable22('signature');
          let serverAddr=this.getQueryVariable22('serverAddr');
          let hospitalId=this.getQueryVariable22('hoscode');
      console.log("sdfdsf",signature,"hospitalId",hospitalId);

                        var targetApp="viewer";
                        var vc = "link"; //vendor code
                        // var hostAddr = "view.blue-imaging.com"; // 蓝影
                        var hostAddr =this.$API.DCM_viewurlv1;
                        //  var hostAddr = "pacs.link-imaging.com";//window.location.host;
                         //Url过期时间（单位为秒）
                        // var expires = data.expires;                 
                        // var signature =data.signature;          
                        // var serverAddr =data.serverAddr;
                        var linkviewurl = "https://" + hostAddr + "/Viewer/Index"
                        linkviewurl = linkviewurl + "?ds=rest" + "&serverAddr=" + serverAddr + "&vc=" + vc +
                        "&expires=" + expires + "&signature=" + signature + "&targetApp=" + targetApp;
                        //  window.open(linkviewurl, "Viewer");//打开连接
                       
                        linkviewurl += "&fmPos=viewer&opts=film&hosId=" + hospitalId;
                        
                       
                        this.dcmviewsrc=linkviewurl;


    },
    methods: {
        submitForm() {
            const loading = this.$loading({text: '登录中'});
            this.$http.post(this.$API.LOGIN,this.param)
            .then((res)=>{
                loading.close();
                console.log('登录信息',res)
                if(res.code == 1){
                   window.sessionStorage.setItem('jqzxUserId', res.data.id)
                    window.sessionStorage.setItem('userName',res.data.account);
                    window.localStorage.setItem('userInfo',JSON.stringify(res.data));
                    if(this.isMobile){
                        Toast.success('登录成功');
                    }else{
                        this.$message.success('登录成功');
                    }
                    this.$router.push('/');
                }else{
                    if(this.isMobile){
                        Toast.fail(res.msg);
                    }else{
                        this.$message.error(res.msg);
                    }
                }
            })
            .catch((err)=>{
                    this.$message.error('');
                    console.log('error submit!!');
                    return false;
            })
        },
        getQueryVariable(variable) {
            var query = window.location.hash,vars=[];
            if(query && query.indexOf('?')!==-1){
                 vars = query.split("?");
            }
            for (var i = 0; i < vars.length; i++) {
                var pair = vars[i].split("=");
                if (pair[0] == variable) { return decodeURIComponent(pair[1]); }
            }
            return '';
        },
           getQueryVariable22(variable){
                //var query = window.location.search.substring(1);
                var query = window.location.href;         
                var vars = query.split("&");
                // console.log('*************************jwtToken22221',query)
                for (var i = 0; i < vars.length; i++) {
                    var pair = vars[i].split("=");
                    if (pair[0] == variable) {
                        return pair[1];
                    }
                }
                return '';
            }
    },
};
</script>

<style scoped>
.login-mobile-wrap {
    position: relative;
    width: 100%;
    height: 100%;
    background: #409EFF;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ms-mobile-login{
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.5);
    overflow: hidden;
    padding-top:20px;
    width: 85%;
}
.login-wrap {
    position: relative;
    width: 100%;
    height: 100%;
    /* background: url('../assets/img/login-bg.png') center no-repeat; */
    background-size: 100%;
}
.el-button--primary{
  background-color: #db511f;
  border-color: #db511f;
}
.ms-title {
    width: 100%;
    line-height: 50px;
    text-align: center;
    font-size: 20px;
    color: #db511f;
    border-bottom: 1px solid #ddd;
    font-weight: bold;
}
.ms-logo{
  height: 50px;
  /* background: url('../assets/img/logo.png') center no-repeat; */
  background-size: auto 50px;
}
.ms-login {
    position: absolute;
    right: 20%;
    top: 50%;
    width: 350px;
    margin: -190px 0 0 -175px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.5);
    overflow: hidden;
    padding-top:20px;
}
.ms-content {
    padding: 30px 30px;
}
.login-btn {
    text-align: center;
    font-size: 0;
}
.login-btn button {
    width: 100%;
    height: 36px;
    margin-bottom: 10px;
}
.login-tips {
    font-size: 12px;
    line-height: 30px;
    color: #fff;
}
</style>